package cn.kongwg.demo01;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

/**
 * @author kongwg
 * @create 2021-05-22 20:37
 */
public class Newdate {
    public static void main(String[] args) {

        //当前时区时间
        ZonedDateTime zonedDateTime = ZonedDateTime.now();
        System.out.println("当前时区时间: " + zonedDateTime);

//
//        LocalDate today = LocalDate.now();
//        //获取当前月第一天：
//        LocalDate firstDayOfThisMonth = today.with(TemporalAdjusters.firstDayOfMonth());
//        // 取本月最后一天
//        LocalDate lastDayOfThisMonth = today.with(TemporalAdjusters.lastDayOfMonth());
//        //取下一天：
//        LocalDate nextDay = lastDayOfThisMonth.plusDays(1);
//        //当年最后一天
//        LocalDate lastday = today.with(TemporalAdjusters.lastDayOfYear());
//        //2021年最后一个周日，如果用Calendar是不得烦死。
//        LocalDate lastMondayOf2021 = LocalDate.parse("2021-12-31").with(TemporalAdjusters.lastInMonth(DayOfWeek.SUNDAY));
//        System.out.println("lastMondayOf2021 = " + lastMondayOf2021);

//        LocalDate now = LocalDate.now();
//        now.plus(1, ChronoUnit.WEEKS)

//        LocalDate date = LocalDate.of(2021, 1, 26);
//        LocalDate parse = LocalDate.parse("2021-01-26");
//        System.out.println("date = " + date);
//        System.out.println("parse = " + parse);
//        System.out.println("---------------------");
//        LocalDateTime dateTime = LocalDateTime.of(2021, 1, 26, 12, 12, 22);
//        LocalDateTime parse1 = LocalDateTime.parse("2021-01-26 12:12:22");
//        System.out.println("dateTime = " + dateTime);
//        System.out.println("parse1 = " + parse1);
//        System.out.println("--------");
//        LocalTime time = LocalTime.of(12, 12, 22);
//        LocalTime parse2 = LocalTime.parse("12:12:22");
//        System.out.println("time = " + time);
//        System.out.println(parse2);


    }

    private static void test1() {
        //format yyyy-MM-dd
        LocalDate date = LocalDate.now();
        System.out.println(String.format("date format : %s", date));

        //format HH:mm:ss
        LocalTime time = LocalTime.now().withNano(0);
        System.out.println(String.format("time format : %s", time));

        //format yyyy-MM-dd HH:mm:ss
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(String.format("dateTime format : %s", dateTimeFormatter));
    }

}
